import { applyMiddleware, createStore } from 'redux'
import rootReducer from './reducer'
// thunk 中间件，用于处理异步 action
import thunk from 'redux-thunk'
// 调试工具配置
import { composeWithDevTools } from 'redux-devtools-extension'
// import { ChannelState } from './reducer/channel'
// import { NewsState } from './reducer/news'

// 应用中间件
const store = createStore(rootReducer, composeWithDevTools(applyMiddleware(thunk)))

// RootState 包含所有模块 state
// export type RootState = {
//   channel: ChannelState
//   news: NewsState
// }

// const fn = (val: number): number => {
//   return val
// }
// // 获取函数类型
// type FnType = typeof fn
// // 结果： type FnType = (val: number) => number
// // 获取函数返回值类型
// type FnReturnType = ReturnType<typeof fn>
// // 结果：type FnReturnType = number

// console.log(111, store)
// dispatch 类型封装：AppDispatch
export type AppDispatch = typeof store.dispatch
// 根 state 类型封装：RootState
export type RootState = ReturnType<typeof store.getState>

export default store
